#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QFile>
#include <QKeyEvent>
#include<QCoreApplication>
#include<QDir>
#include <QTextStream>
#include<QRandomGenerator>
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    ,m_ptrStuSql(nullptr)
{
    ui->setupUi(this);

    QFile f;
    f.setFileName(":/css/stuqssloginwindow.css");
    f.open(QIODevice::ReadOnly);
    QString mldcss = f.readAll();
    m_dlgLogin.setStyleSheet(mldcss);
    f.close();
    f.setFileName(":/css/stuqssmainwindow.css");
    f.open(QIODevice::ReadOnly);
    QString maincss = f.readAll();
    this->setStyleSheet(maincss);
    f.close();



    m_dlgLogin.show();
    auto main = [&](){
        this->show();
    };
    connect(&m_dlgLogin,&Page_Login::sendLoginSuccess,this,main);

    ui->treeWidget->clear();
    ui->treeWidget->setColumnCount(1);

    QStringList l;
    l<<"学生信息管理系统";
    QTreeWidgetItem *pf = new QTreeWidgetItem(ui->treeWidget,l);
    ui->treeWidget->addTopLevelItem(pf);
    QTreeWidgetItem *pl = new QTreeWidgetItem(pf,QStringList("学生管理"));
    ui->treeWidget->addTopLevelItem(pl);
    QTreeWidgetItem *pr = new QTreeWidgetItem(pf,QStringList("管理员管理"));
    ui->treeWidget->addTopLevelItem(pl);
    pf->addChild(pl);
    pf->addChild(pr);

    ui->treeWidget->expandAll();
    ui->stackedWidget->setCurrentIndex(0);

    m_ptrStuSql = stuSql::getinstance();
    m_ptrStuSql->init();

    m_lNames<<"柴静芙 ";
    m_lNames<<"遇觅风 ";
    m_lNames<<"范姜弘博";
    m_lNames<<"水绮丽 ";
    m_lNames<<"房志义 ";
    m_lNames<<"召元彤 ";
    m_lNames<<"庄念露 ";
    m_lNames<<"狂芳苓 ";
    m_lNames<<"韩怡  ";
    m_lNames<<"道和泽 ";
    m_lNames<<"钦乐心 ";
    m_lNames<<"鄢志诚 ";
    m_lNames<<"敛燕妮 ";
    m_lNames<<"端彰  ";
    m_lNames<<"吕之卉 ";
    m_lNames<<"帖心香 ";
    m_lNames<<"慈醉柳 ";
    m_lNames<<"青雅萍 ";
    m_lNames<<"尉映冬 ";
    m_lNames<<"彤采蓝 ";
    m_lNames<<"堵青香 ";
    m_lNames<<"佛嘉宝 ";
    m_lNames<<"魏瑛  ";
    m_lNames<<"祖依秋 ";
    m_lNames<<"势嘉年 ";
    m_lNames<<"惠正  ";
    m_lNames<<"岳忆雪 ";
    m_lNames<<"钱书蝶 ";
    m_lNames<<"庆慧巧 ";
    m_lNames<<"杜允  ";
    m_lNames<<"环菊月 ";
    m_lNames<<"修茹薇 ";
    m_lNames<<"贸觅晴 ";
    m_lNames<<"宫妙菡 ";
    m_lNames<<"毋曦  ";
    m_lNames<<"函俊健 ";
    m_lNames<<"紫巧香 ";
    m_lNames<<"酒莺韵 ";
    m_lNames<<"倪旋  ";
    m_lNames<<"宦婉慧 ";
    m_lNames<<"赫音仪 ";
    m_lNames<<"能成化 ";
    m_lNames<<"逢宾  ";
    m_lNames<<"种痴旋 ";
    m_lNames<<"睢歆美 ";
    m_lNames<<"乌璇子 ";
    m_lNames<<"朋春竹 ";
    m_lNames<<"马佳梦寒";
    m_lNames<<"连志文 ";
    m_lNames<<"张知  ";
    m_lNames<<"冼映寒 ";
    m_lNames<<"九思若 ";
    m_lNames<<"过烨烁 ";
    m_lNames<<"悉正真 ";
    m_lNames<<"斐菊华 ";
    m_lNames<<"定齐敏 ";
    m_lNames<<"虎绮烟 ";
    m_lNames<<"无问梅 ";
    m_lNames<<"琦音  ";
    m_lNames<<"么芮优 ";
    m_lNames<<"摩琇芬 ";
    m_lNames<<"敬吉玟 ";
    m_lNames<<"巩安晏 ";
    m_lNames<<"苑紫云 ";
    m_lNames<<"泣瑛瑶 ";
    m_lNames<<"杭锦文 ";
    m_lNames<<"愈和玉 ";
    m_lNames<<"徭凯凯 ";
    m_lNames<<"长幻梅 ";
    m_lNames<<"寿昆谊 ";
    m_lNames<<"蔺夏柳 ";
    m_lNames<<"辛芳春 ";
    m_lNames<<"老玑  ";
    m_lNames<<"公逸馨 ";
    m_lNames<<"羊舌清韵";
    m_lNames<<"姓慕雁 ";
    m_lNames<<"巧灵韵 ";
    m_lNames<<"赛雅致 ";
    m_lNames<<"戈丹亦 ";
    m_lNames<<"邛田田 ";
    m_lNames<<"周霖  ";
    m_lNames<<"希笑槐 ";
    m_lNames<<"问举  ";
    m_lNames<<"牟暮  ";
    m_lNames<<"廖晓旋 ";
    m_lNames<<"郎觅山 ";
    m_lNames<<"眭蔼  ";
    m_lNames<<"何清馨 ";
    m_lNames<<"节安静 ";
    m_lNames<<"檀化  ";
    m_lNames<<"代英发 ";
    m_lNames<<"库瑶瑾 ";
    m_lNames<<"植慧晨 ";
    m_lNames<<"糜瀚文 ";
    m_lNames<<"驹尔容 ";
    m_lNames<<"从丽思 ";
    m_lNames<<"谷薇歌 ";
    m_lNames<<"干昊然 ";
    m_lNames<<"甫晨潍 ";
    m_lNames<<"首晨萱 ";
    m_lNames<<"藏访波 ";
    m_lNames<<"千晶辉 ";
    m_lNames<<"相雪绿 ";
    m_lNames<<"委愉  ";
    m_lNames<<"纳喇清舒";
    m_lNames<<"塔濯  ";
    m_lNames<<"肇滢滢 ";
    m_lNames<<"矫洁  ";
    m_lNames<<"濯天工 ";
    m_lNames<<"镜景龙 ";
    m_lNames<<"麻莎莉 ";
    m_lNames<<"祈起运 ";
    m_lNames<<"弓夏岚 ";
    m_lNames<<"侨和悦 ";
    m_lNames<<"夷雪瑶 ";
    m_lNames<<"员献仪 ";
    m_lNames<<"说景焕 ";
    m_lNames<<"实和煦 ";
    m_lNames<<"秘沛春 ";
    m_lNames<<"笃寻菱 ";
    m_lNames<<"余吉星 ";
    m_lNames<<"桓孤兰 ";
    m_lNames<<"米昆锐 ";
    m_lNames<<"野宏朗 ";
    m_lNames<<"闭添  ";
    m_lNames<<"穆北辰 ";
    m_lNames<<"柳清妍 ";
    m_lNames<<"福雪漫 ";
    m_lNames<<"普志用 ";
    m_lNames<<"隐念霜 ";
    m_lNames<<"寸梦竹 ";
    m_lNames<<"万俟玉石";
    m_lNames<<"郦梦寒 ";
    m_lNames<<"殷苓  ";
    m_lNames<<"贡俊明 ";
    m_lNames<<"王采春 ";
    m_lNames<<"诸葛思博";
    m_lNames<<"暴冷玉 ";
    m_lNames<<"拓跋如仪";
    m_lNames<<"留囡  ";
    m_lNames<<"苗白  ";
    m_lNames<<"胥青香 ";
    m_lNames<<"宜向秋 ";
    m_lNames<<"象丰  ";
    m_lNames<<"苦初露 ";
    m_lNames<<"务红叶 ";
    m_lNames<<"太史其 ";
    m_lNames<<"言成济 ";
    m_lNames<<"羊嫒  ";
    m_lNames<<"百里心水";
    m_lNames<<"呼白梦 ";
    m_lNames<<"瓮笑雯 ";
    m_lNames<<"籍嘉澍 ";
    m_lNames<<"苟裕  ";
    m_lNames<<"海智纯 ";
    m_lNames<<"宾吉敏 ";
    m_lNames<<"经彦杉 ";
    m_lNames<<"仲孙诗柳";
    m_lNames<<"仰悦恺 ";
    m_lNames<<"类秀艳 ";
    m_lNames<<"云山柳 ";
    m_lNames<<"奇怀桃 ";
    m_lNames<<"冒巧春 ";
    m_lNames<<"上官高驰";
    m_lNames<<"窦痴海 ";
    m_lNames<<"冀高  ";
    m_lNames<<"建凯捷 ";
    m_lNames<<"释瀚钰 ";
    m_lNames<<"竹南霜 ";
    m_lNames<<"饶豪  ";
    m_lNames<<"诺娅欣 ";
    m_lNames<<"甲伟懋 ";
    m_lNames<<"陈莹琇 ";
    m_lNames<<"祭高达 ";
    m_lNames<<"汗可可 ";
    m_lNames<<"邬良奥 ";
    m_lNames<<"卓竹萱 ";
    m_lNames<<"疏傲南 ";
    m_lNames<<"傅翱  ";
    m_lNames<<"绪祺  ";
    m_lNames<<"墨夜梅 ";
    m_lNames<<"栋骄  ";
    m_lNames<<"悟代桃 ";
    m_lNames<<"钊金  ";
    m_lNames<<"回寄灵 ";
    m_lNames<<"光映寒 ";
    m_lNames<<"淳于果 ";
    m_lNames<<"寇诚  ";
    m_lNames<<"莱冰夏 ";
    m_lNames<<"牛兴修 ";
    m_lNames<<"夫令梓 ";
    m_lNames<<"庚海蓝 ";
    m_lNames<<"折飞荷 ";
    m_lNames<<"侍飞龙 ";
    m_lNames<<"朱访梦 ";
    m_lNames<<"严芷珊 ";
    m_lNames<<"集卿  ";
    m_lNames<<"占志国 ";
    m_lNames<<"牢幼霜 ";
    m_lNames<<"独同光 ";
    m_lNames<<"泥雨筠 ";
    m_lNames<<"烟浩宕 ";
    m_lNames<<"黄高丽 ";
    m_lNames<<"合梓童 ";
    m_lNames<<"蒋幼菱 ";
    m_lNames<<"隗聪  ";
    m_lNames<<"蛮永贞 ";
    m_lNames<<"进元芹 ";
    m_lNames<<"洪翰藻 ";
    m_lNames<<"吉兴庆 ";
    m_lNames<<"卫晨曦 ";
    m_lNames<<"巴沙羽 ";
    m_lNames<<"壬光辉 ";
    m_lNames<<"蒯宛  ";
    m_lNames<<"蒲光启 ";
    m_lNames<<"湛梓楠 ";
    m_lNames<<"仍和悌 ";
    m_lNames<<"频兰娜 ";
    m_lNames<<"董芝英 ";
    m_lNames<<"章淑  ";
    m_lNames<<"祝博学 ";
    m_lNames<<"公叔格菲";
    m_lNames<<"鄞明辉 ";
    m_lNames<<"威淼  ";
    m_lNames<<"甘冰安 ";
    m_lNames<<"伊素怀 ";
    m_lNames<<"业春绿 ";
    m_lNames<<"陶静涵 ";
    m_lNames<<"兰伟博 ";
    m_lNames<<"念雅懿 ";
    m_lNames<<"爱谨  ";
    m_lNames<<"佘宵晨 ";
    m_lNames<<"让嘉禾 ";
    m_lNames<<"营谷芹 ";
    m_lNames<<"弘建华 ";
    m_lNames<<"波笑南 ";
    m_lNames<<"错白容 ";
    m_lNames<<"褒宏达 ";
    m_lNames<<"毕雨旋 ";
    m_lNames<<"充复  ";
    m_lNames<<"楼芬馥 ";
    m_lNames<<"文昂然 ";
    m_lNames<<"塞涵衍 ";
    m_lNames<<"屠代芙 ";
    m_lNames<<"佴尔真 ";
    m_lNames<<"东光远 ";
    m_lNames<<"用梦菲 ";
    m_lNames<<"衣芷蓝 ";
    m_lNames<<"金冷松 ";
    m_lNames<<"邹盼夏 ";
    m_lNames<<"蒙萝  ";
    m_lNames<<"仵乐英 ";
    m_lNames<<"范紫萍 ";
    m_lNames<<"崇华采 ";
    m_lNames<<"霍霞影 ";
    m_lNames<<"子车青枫";
    m_lNames<<"刀恨云 ";
    m_lNames<<"和彤  ";
    m_lNames<<"闵静枫 ";
    m_lNames<<"令狐又绿";
    m_lNames<<"皇甫贞 ";
    m_lNames<<"贝俊民 ";
    m_lNames<<"郯问儿 ";
    m_lNames<<"其静淑 ";
    m_lNames<<"昝冰蓝 ";
    m_lNames<<"顿星剑 ";
    m_lNames<<"资文光 ";
    m_lNames<<"枚安青 ";
    m_lNames<<"守语山 ";
    m_lNames<<"邓俊风 ";
    m_lNames<<"袭傲柔 ";
    m_lNames<<"习运珊 ";
    m_lNames<<"犁骞北 ";
    m_lNames<<"蚁新雅 ";
    m_lNames<<"莫笑容 ";
    m_lNames<<"汉晓莉 ";
    m_lNames<<"荣芸茗 ";
    m_lNames<<"薄天佑 ";
    m_lNames<<"曹航  ";
    m_lNames<<"桥元蝶 ";
    m_lNames<<"拱璧  ";
    m_lNames<<"於若南 ";
    m_lNames<<"闪骞泽 ";
    m_lNames<<"谷梁妃 ";
    m_lNames<<"尉迟紫菱";
    m_lNames<<"邝新文 ";
    m_lNames<<"广闲静 ";
    m_lNames<<"彭芷荷 ";
    m_lNames<<"澄若星 ";
    m_lNames<<"乘朝旭 ";
    m_lNames<<"谭曼寒 ";
    m_lNames<<"卜凌波 ";
    m_lNames<<"亢琨瑜 ";
    m_lNames<<"出尧  ";
    m_lNames<<"蓝逸致 ";
    m_lNames<<"理修谨 ";
    m_lNames<<"尧忆安 ";
    m_lNames<<"性千雁 ";
    m_lNames<<"费莫衣 ";
    m_lNames<<"蒉帆  ";
    m_lNames<<"幸浩邈 ";
    m_lNames<<"续坚成 ";
    m_lNames<<"仆陶宁 ";
    m_lNames<<"皮晓兰 ";
    m_lNames<<"邴清漪 ";
    m_lNames<<"符昊空 ";
    m_lNames<<"抗紫杉 ";
    m_lNames<<"祢星宇 ";
    m_lNames<<"力石  ";
    m_lNames<<"枝炳  ";
    m_lNames<<"璩融雪 ";
    m_lNames<<"燕怡君 ";
    m_lNames<<"戎情  ";
    m_lNames<<"仁向露 ";
    m_lNames<<"慎恺  ";
    m_lNames<<"豆兴言 ";
    m_lNames<<"迮白翠 ";
    m_lNames<<"袁孟君 ";
    m_lNames<<"赵颖初 ";
    m_lNames<<"都丽佳 ";
    m_lNames<<"滑易梦 ";
    m_lNames<<"圣梦之 ";
    m_lNames<<"扬妍丽 ";
    m_lNames<<"贲之桃 ";
    m_lNames<<"应如南 ";
    m_lNames<<"濮阳凝冬";
    m_lNames<<"寒德运 ";
    m_lNames<<"濮春晖 ";
    m_lNames<<"匡丰熙 ";
    m_lNames<<"肖秋巧 ";
    m_lNames<<"廉嫣  ";
    m_lNames<<"锁水丹 ";
    m_lNames<<"户涉  ";
    m_lNames<<"玉虹彩 ";
    m_lNames<<"衡曼吟 ";
    m_lNames<<"堂雅楠 ";
    m_lNames<<"伏香柏 ";
    m_lNames<<"家芳洲 ";
    m_lNames<<"盈明哲 ";
    m_lNames<<"竺甘雨 ";
    m_lNames<<"韶新洁 ";
    m_lNames<<"保振荣 ";
    m_lNames<<"强新雪 ";
    m_lNames<<"裴君博 ";
    m_lNames<<"古香薇 ";
    m_lNames<<"羽浩淼 ";
    m_lNames<<"颛孙夏兰";
    m_lNames<<"西门玛丽";
    m_lNames<<"所梦华 ";
    m_lNames<<"依思涵 ";
    m_lNames<<"帛健  ";
    m_lNames<<"太叔宜然";
    m_lNames<<"碧鲁代天";
    m_lNames<<"郑修杰 ";
    m_lNames<<"尹骞魁 ";
    m_lNames<<"梁丘枫 ";
    m_lNames<<"前安萱 ";
    m_lNames<<"颜迎夏 ";
    m_lNames<<"利惜蕊 ";
    m_lNames<<"森文  ";
    m_lNames<<"恽惜萱 ";
    m_lNames<<"扶雪兰 ";
    m_lNames<<"艾欣可 ";
    m_lNames<<"封健柏 ";
    m_lNames<<"母歆然 ";
    m_lNames<<"逄新雨 ";
    m_lNames<<"崔雅爱 ";
    m_lNames<<"叔画  ";
    m_lNames<<"义畅  ";
    m_lNames<<"勇水凡 ";


    updateTable();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::keyPressEvent(QKeyEvent *event)
{
//    if(event->key() == Qt::Key_F6)
//    {
//        QFile f;
//        auto csspath = QCoreApplication::applicationDirPath()+QDir::separator()+"stuqss.css";
//        f.setFileName(csspath);
//        f.open(QIODevice::ReadOnly);
//        QString strQss = f.readAll();
//        this->setStyleSheet(strQss);
//        m_dlgLogin.setStyleSheet(strQss);
//    }
    if(event->key() == Qt::Key_F6)
    {

    }
    if(event->key() == Qt::Key_F7)
    {

    }
}


void MainWindow::on_btn_exit_clicked()
{
    exit(0);
}



void MainWindow::on_btn_simulation_clicked()
{
    QRandomGenerator g,c;
    g.seed(0);
    c.seed(0);

    //制作一千条学生数据、
    for (int i=0; i <m_lNames.size(); ++i) {
        auto grade = g.bounded(7,10);
        auto uiclass = c.bounded(1,8);
        StuInfo info;
        info.name = m_lNames[i];
        if(i%3)
        {
            info.age = 16;
        }
        if(i%2)
        {
            info.age = 18;
        }
        if(i%7)
        {
            info.age = 17;
        }

        info.grade = grade;
        info.uiclass = uiclass;
        info.studentid = i+1;
        info.phone = "12345678911";
        info.wechat = "12345678911";
        m_ptrStuSql->addStu(info);
    }
}

void MainWindow::on_btn_add_clicked()
{
    m_dlgAddStu.setType(true);
    m_dlgAddStu.exec();
    updateTable();
}



//void MainWindow::on_label_5_linkActivated(const QString &link)
//{

//}

void MainWindow::on_pushButton_clicked()
{
    m_ptrStuSql->clearStuTable();
    updateTable();
}

void MainWindow::updateTable()
{
    ui->tableWidget->clear();
    ui->tableWidget->setColumnCount(9);
    QStringList l;
    l<<"序号"<<"ID"<<"姓名"<<"年龄"<<"年级"<<"班级"<<"学号"<<"电话"<<"微信";
    //将l中的字符串水平列展示在表格中，以此不用在ui设计里面添加
    ui->tableWidget->setHorizontalHeaderLabels(l);
    //只选中行
    ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
    auto cnt = m_ptrStuSql->getStuCnt();

    QList<StuInfo> lStudents = m_ptrStuSql->getPageStu(0,cnt);


    ui->tableWidget->setRowCount(cnt);
    for (int i =0;i<lStudents.size();++i)
    {
        ui->tableWidget->setItem(i,0,new QTableWidgetItem(QString::number(i)));
        ui->tableWidget->setItem(i,1,new QTableWidgetItem(QString::number(lStudents[i].id)));
        ui->tableWidget->setItem(i,2,new QTableWidgetItem(lStudents[i].name));
        ui->tableWidget->setItem(i,3,new QTableWidgetItem(QString::number(lStudents[i].age)));
        ui->tableWidget->setItem(i,4,new QTableWidgetItem(QString::number(lStudents[i].grade)));
        ui->tableWidget->setItem(i,5,new QTableWidgetItem(QString::number(lStudents[i].uiclass)));
        ui->tableWidget->setItem(i,6,new QTableWidgetItem(QString::number(lStudents[i].studentid)));
        ui->tableWidget->setItem(i,7,new QTableWidgetItem(lStudents[i].phone));
        ui->tableWidget->setItem(i,8,new QTableWidgetItem(lStudents[i].wechat));

    }
}

void MainWindow::on_btn_del_clicked()
{
    int i = ui->tableWidget->currentRow();
    if(i>=0)
    {
        int id = ui->tableWidget->item(i,1)->text().toUInt();
        bool flag = m_ptrStuSql->delStu(id);
        if(flag)
        {
            QMessageBox::information(nullptr,"信息","删除成功");
            updateTable();
        }


    }

}

void MainWindow::on_btn_edit_clicked()
{
    StuInfo info;
    int i = ui->tableWidget->currentRow();
    if(i>=0)
    {
        info.id = ui->tableWidget->item(i,1)->text().toUInt();
        info.name = ui->tableWidget->item(i,2)->text();
        info.age = ui->tableWidget->item(i,3)->text().toUInt();
        info.grade = ui->tableWidget->item(i,4)->text().toUInt();
        info.uiclass = ui->tableWidget->item(i,5)->text().toUInt();
        info.studentid = ui->tableWidget->item(i,6)->text().toUInt();
        info.phone = ui->tableWidget->item(i,7)->text();
        info.wechat = ui->tableWidget->item(i,8)->text();
        m_dlgAddStu.setType(false,info);
        m_dlgAddStu.exec();
    }

    updateTable();
}

void MainWindow::on_btn_search_clicked()
{
    QString strFilter = ui->le_search->text();
    if(strFilter.isEmpty())
    {
        QMessageBox::information(nullptr,"警告","筛选栏为空");
        updateTable();
        return;
    }
    ui->tableWidget->clear();
    ui->tableWidget->setColumnCount(9);
    QStringList l;
    l<<"序号"<<"ID"<<"姓名"<<"年龄"<<"年级"<<"班级"<<"学号"<<"电话"<<"微信";
    //将l中的字符串水平列展示在表格中，以此不用在ui设计里面添加
    ui->tableWidget->setHorizontalHeaderLabels(l);
    //只选中行
    ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
    auto cnt = m_ptrStuSql->getStuCnt();


    QList<StuInfo> lStudents = m_ptrStuSql->getPageStu(0,cnt);



    int index = 0;
    for (int i =0;i<lStudents.size();++i)
    {
        if(!lStudents[i].name.contains(strFilter))
        {
            continue;
        }
        ui->tableWidget->setItem(index,0,new QTableWidgetItem(QString::number(index+1)));
        ui->tableWidget->setItem(index,1,new QTableWidgetItem(QString::number(lStudents[i].id)));
        ui->tableWidget->setItem(index,2,new QTableWidgetItem(lStudents[i].name));
        ui->tableWidget->setItem(index,3,new QTableWidgetItem(QString::number(lStudents[i].age)));
        ui->tableWidget->setItem(index,4,new QTableWidgetItem(QString::number(lStudents[i].grade)));
        ui->tableWidget->setItem(index,5,new QTableWidgetItem(QString::number(lStudents[i].uiclass)));
        ui->tableWidget->setItem(index,6,new QTableWidgetItem(QString::number(lStudents[i].studentid)));
        ui->tableWidget->setItem(index,7,new QTableWidgetItem(lStudents[i].phone));
        ui->tableWidget->setItem(index,8,new QTableWidgetItem(lStudents[i].wechat));
        ++index;
    }
    ui->tableWidget->setRowCount(index);
}
